package com.woohua.demo.thread.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.CountDownLatch;

/**
 * @version 1.0
 * @author: woo hua
 * @DATE 2022/7/21 9:22
 * @description:异步任务
 */
@Slf4j
@Component
public class AsyncTask {


    /**
     * myTaskAsyncPool即配置线程池的方法名，此处如果不写自定义线程池的方法名，会使用默认的线程池
     * @param i
     * @param countDownLatch
     * @throws InterruptedException
     */
    @Async("myTaskAsyncPool")
    public void doTask1(int i, CountDownLatch countDownLatch) throws InterruptedException{
        log.info("Task"+i+" started.");
        // 线程执行完，计数器 -1
        countDownLatch.countDown();
    }
}
